/**
 * Copyright 2009 by Christian Scheid. This file is part of the switch eclipse plugin and is licensed under the
 * GPL version 3. Please refer to the URL http://www.gnu.org/licenses/gpl-3.0.html for details.
 */
package org.digitalsoul.switchplugin.patterns;


import org.digitalsoul.switchplugin.SwitchFile;



public class FileExtensionPattern implements IPattern {

    private String fileExtension;
    
    public FileExtensionPattern(String fileExtension) {
        this.fileExtension = fileExtension.replaceAll("\\.", "");
    }
    
    public String getFileExtension() {
        return fileExtension;
    }

    public boolean matches(SwitchFile file) {
        return file.getFileExtension().equals(fileExtension);
    }
    
    public SwitchFile applyToFile(IPattern previousPattern, SwitchFile file) {
        file.changeFileExtension(getFileExtension());
        return file; 
    }
    
    @Override
    public String toString() {
        return "file-extension: " + getFileExtension();
    }

    public SwitchFile undoFile(SwitchFile file) {
        return file;
    }
    
    public PatternType getType() {
        return PatternType.FILENAME_EXTENSION;
    }
}
